let tool = {
  getCustomTime: (time, type = "YYYY-MM-DD hh:mm:ss") => {
    let date = "";
    if (time) {
      if (typeof time == "string") {
        time = time.replace(/\-/g, "/");
        time = time.replace(/\./g, "/");
      }
      date = new Date(time);
    } else {
      date = new Date();
    }
    if (type == "timestamp") {
      return date.getTime();
    }

    let YYYY = date.getFullYear();

    //月
    let M = date.getMonth() + 1;
    let MM = M.toString().padStart(2, "0");

    //日
    let D = date.getDate();
    let DD = D.toString().padStart(2, "0");

    //时
    let h = date.getHours();
    let hh = h.toString().padStart(2, "0");

    //分
    let m = date.getMinutes();
    let mm = m.toString().padStart(2, "0");

    //秒
    let s = date.getSeconds();
    let ss = s.toString().padStart(2, "0");

    let week = date.getDay();

    type = type.replace(/YYYY/g, YYYY);

    type = type.replace(/MM/g, MM);
    type = type.replace(/M/g, M);

    type = type.replace(/DD/g, DD);
    type = type.replace(/D/g, D);

    type = type.replace(/hh/g, hh);
    type = type.replace(/h/g, h);

    type = type.replace(/mm/g, mm);
    type = type.replace(/m/g, m);

    type = type.replace(/ss/g, ss);
    type = type.replace(/s/g, s);

    type = type.replace(/week/g, week);
    return type;
  },
};

export default tool;
